package com.example.hps.greendaotest.dao;

import android.content.Context;

import com.example.hps.greendaotest.gen.DaoMaster;
import com.example.hps.greendaotest.gen.DaoSession;

/**
 * Created by hps on 17-5-1.
 */

public class DbHelper {
    private static DaoMaster daoMaster;
    private static DaoSession daoSession;

    private DbHelper() {}

    public static DaoMaster getDaoMaster(Context context) {
        if(daoMaster == null) {
            DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "users.db", null);
            daoMaster = new DaoMaster(helper.getWritableDatabase());
        }

        return daoMaster;
    }

    public static DaoSession getDaoSession(Context context) {
        if(daoMaster == null)
            daoMaster = getDaoMaster(context);
        if(daoSession == null)
            daoSession = daoMaster.newSession();
        return daoSession;
    }
}
